package com.lanqiao.companymanage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lanqiao.companymanage.entity.Cost;
import com.lanqiao.companymanage.entity.Dep;
import com.lanqiao.companymanage.service.CostMessService;
import com.lanqiao.companymanage.service.StaffMessService;
import com.lanqiao.companymanage.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 何小棍
 * 费用信息查看与添加
 */
@RestController
@RequestMapping("/costMess")
@Api(tags = "费用信息")
public class CostMessController {

    @Autowired
    CostMessService costMessService;

    /**
     * 分页查询
     */
    @GetMapping("/costPage")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页数,默认第一页"),
            @ApiImplicitParam(name = "size", value = "每页显示条数，默认 10")})
    @ApiOperation(value = "分页查询")
    public Object costPage(Page<Cost> costPage){
        Page<Cost> page =  costMessService.listPage(costPage);
        return Result.success(page);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("/selectById")
    @ApiOperation(value = "根据id查询")
    public Object selectById(Integer id){
        Cost cost = costMessService.selectById(id);
        if (cost == null) {
            return Result.err("找不到对应id的值");
        }else {
            return Result.success("查询成功",cost);
        }
    }

    /**
     * 费用信息添加
     * @param cost
     * @return
     */
    @PostMapping("/addCost")
    @ApiOperation(value = "费用信息添加")
    public Object addCost(Cost cost){
        int i = costMessService.addCost(cost);
        if (i==0) {
            return Result.err("添加失败");
        }else {
            return Result.success("添加成功",null);
        }
    }

    /**
     * 根据id删除
     */
    @GetMapping("/deletedById")
    @ApiOperation(value = "根据id删除")
    public Object deletedById(Integer id)  {
        int i = costMessService.deleteById(id);
        if (i==0) {
            return Result.err("删除失败");
        }else {
            return Result.success("删除成功",null);
        }
    }

    /**
     * 根据id修改
     */
    @PostMapping("/updateCost")
    @ApiOperation(value = "根据id修改")
    public Object updateCost(Cost cost)  {
        int i = costMessService.updateCost(cost);
        if (i==0) {
            return Result.err("修改失败");
        }else {
            return Result.success("修改成功",null);
        }
    }

}
